import 'package:cms/components/term_items.dart';
import 'package:cms/views/list_views/state/cubit/term_list_cubit.dart';
import 'package:cms/views/list_views/state/cubit/term_list_state.dart';
import 'package:common/export/bloc.dart';
import 'package:flutter/material.dart';
import 'package:common/export/tools.dart';

class LaraPressTermListView extends StatelessWidget {
  final String searchKeyword;
  const LaraPressTermListView({super.key, this.searchKeyword = ''});

  @override
  Widget build(BuildContext context) {
    return BlocProvider(
      create: (context) => TermListCubit(searchKeyword: searchKeyword),
      child: Builder(builder: (context) => _buildPage(context)),
    );
  }

  Widget _buildPage(BuildContext context) {
    final cubit = BlocProvider.of<TermListCubit>(context);
    return BlocBuilder<TermListCubit, TermListState>(
      builder: (context, state) {
        return CustomScrollView(
          slivers: [
            SliverList.separated(
              itemCount: cubit.state.list.length,
              itemBuilder: (context, index) {
                return LaraPressTermRowImg(term: cubit.state.list[index]);
              },
              separatorBuilder: (context, index) => SizedBox(height: .5.h),
            ),
          ],
        );
      },
    );
  }
}
